const $api = require('./../../utils/request').API;


Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    active: '',
    activeRoom:null,
    more: true,
    RoomList: [],
    pageSize: 10,
    pageNum: 1,
    choseData:{},
    btnStaus:false,
    selectedAll: false
  },

  onClick(event) {
    this.setData({
      active: event.detail.name,
      activeRoom:null
    });
    
    let stataus =  Number(event.detail.name);
    this.getRoomList(stataus)
  },



 

  choseRoom(e){
      this.setData({
        activeRoom:e.currentTarget.dataset.index,
        choseData:e.currentTarget.dataset.item,
        btnStaus:true
      });
  },

  onSubmit(){
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2]; 
    prevPage.setData({  
      room: this.data.choseData
    });
    wx.navigateBack({
      delta: 1
    })
  },

  getRoomList(roomStatus){
    wx.showLoading({
      title: '正在加载',
    })
    this.setData({
      loading:true
    })
    let Status = roomStatus?roomStatus:'';
    $api.roomList({roomStatus:Status}).then(res=>{
      wx.hideLoading({
        fail:()=>{},
        success:()=>{},
        complete: (complete) => {}
      })
      res.list.forEach(e=>{
        if( e.roomStatus == 1 ){
          e.class = 'kxstatus'
        }else if(e.roomStatus == 2){
          e.class = 'systatus'
        }else if(e.roomStatus == 3){
          e.class = 'zfstatus'
        }else if(e.roomStatus == 4){ 
          e.class = 'wxstatus'
        }else if(e.roomStatus == 5){
          e.class = 'ydstatus'
        }
      })
      this.setData({
        RoomList:res.list,
        loading:false
      })
    }).catch(err=>{
      wx.hideLoading({
        fail:()=>{},
        success:()=>{},
        complete: (complete) => {}
      })
      this.setData({
        loading:false
      })
    })
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.selectComponent('#header').resize();
    this.getRoomList();


  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

    this.setData({ 
      list: [],
      pageNum:1,
    })

  },

 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.more) {
      console.log(1111);
    }

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})